package com.crlui.control
{
	import com.crlui.control.skins.ISkin;
	import com.crlui.core.IDatable;
	import com.crlui.event.ResizeEvent;
	
	import flash.display.Sprite;
	
	
	/**
	 * 
	 * @author crl
	 * 
	 */	
	public class UIComponent extends Sprite implements IDatable
	{
		protected var _skin:ISkin;
		protected var _data:*;
		
		protected var _width:Number;
		protected var _height:Number;
		public function UIComponent()
		{
			super();
		}
		
		public function setSkin(value:ISkin):void{
			if(_skin){
				_skin.destory();
			}
			_skin=value;
			if(_skin){
				_skin.initialize(this);
				invalidate();		
			}
		}
		
		
		public function invalidate():void{
			if(_skin){
				_skin.invalidate();
			}
		}
		
		public function get data():*
		{
			
			return _data;
		}
		
		public function set data(value:*):void
		{
			_data=value;
		}
		
		override public function get height():Number
		{
			return _height;
		}
		
		override public function set height(value:Number):void
		{
			if(_height !=value){
				setSize(_width,value);	
			}
		}
		
		override public function get width():Number
		{
			return _width;
		}
		
		override public function set width(value:Number):void
		{
			_width = value;
		}
		
		
		public function setSize(width:Number,height:Number):void{
			if(_width !=width || _height !=height){
				var event:ResizeEvent=new ResizeEvent(ResizeEvent.RESIZE,_width,_height);
				
				_width=width;
				_height=height;
				
				updateSize();
			}
		}
		
		protected function updateSize():void{
			if(_skin){
				_skin.updateSize();
			}
		}
	}
}